package first.group.ssh.authorize;

import first.group.ssh.ConnectionCallback;
import first.group.ssh.PacketConnectStage;
import first.group.ssh.SSHConsts;
import first.group.ssh.packet.UserAuthRequestPacket;
import java.util.List;

public abstract class Authorization extends PacketConnectStage {
    
    public interface AuthorizationCallback {
        void authorizeFailed(List<String> continueMethods, boolean partialSuccess);
        void authorizeSucceed();
    }
    
    protected AuthorizationCallback authorizationCallback;
    protected ConnectionCallback connectionCallback;
    protected String userName;
    
    public void setAuthorizationCallback(AuthorizationCallback authorizationCallback) {
        this.authorizationCallback = authorizationCallback;
    }
    
    public void setConnectionCallback(ConnectionCallback connectionCallback) {
        this.connectionCallback = connectionCallback;
    }
    
    public void setUsername(String userName) {
        this.userName = userName;
    }

    @Override
    public boolean shouldRead() {
        return true;
    }

    @Override
    public void init() {
        connectionCallback.appendPacket(new UserAuthRequestPacket(userName, SSHConsts.SERVICE_NAME_CONNECTION, getName(), getPayload()));
    }
    
    public abstract String getName();
    public abstract byte[] getPayload();
}
